package com.jieao.content.service.impl;

import java.util.List;

import com.jieao.content.domain.Album;
import com.jieao.content.dto.AlbumDto;
import com.jieao.content.mapper.AlbumMapper;
import com.jieao.content.service.IAlbumService;
import com.jieao.framework.util.ShiroUtils;
import org.springframework.stereotype.Service;
import com.jieao.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 图片Service业务层处理
 * @author jieao
 * @date 2020-09-23
 */
@Service
public class AlbumServiceImpl implements IAlbumService {
    @Resource
    private AlbumMapper albumMapper;

    /**
     * 查询图片
     * @param id 图片ID
     * @return 图片
     */
    @Override
    public AlbumDto selectAlbumById(Long id) {
        return albumMapper.selectAlbumById(id);
    }

    /**
     * 查询图片列表
     * @param album 图片
     * @return 图片
     */
    @Override
    public List<AlbumDto> selectAlbumList(Album album) {
        return albumMapper.selectAlbumList(album);
    }

    /**
     * 新增图片
     * @param album 图片
     * @return 结果
     */
    @Override
    public int insertAlbum(Album album) {
        String albumSort = "0000"+album.getAlbumSort();
        album.setAlbumSort(albumSort.substring(albumSort.length()-4));

        album.setCreateBy(ShiroUtils.getUserId().toString());
        return albumMapper.insertAlbum(album);
    }

    /**
     * 修改图片
     * @param album 图片
     * @return 结果
     */
    @Override
    public int updateAlbum(Album album) {
        album.setUpdateBy(ShiroUtils.getUserId().toString());
        return albumMapper.updateAlbum(album);
    }

    /**
     * 删除图片对象
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAlbumByIds(String ids) {
        String[] strings = Convert.toStrArray(ids);
        int i = 0;
        for (String id : strings) {
            Album album = albumMapper.selectAlbumById(Long.valueOf(id));
        }
        return albumMapper.deleteAlbumByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除图片信息
     * @param id 图片ID
     * @return 结果
     */
    @Override
    public int deleteAlbumById(Long id) {
        Album album = albumMapper.selectAlbumById(id);
        return albumMapper.deleteAlbumById(id);
    }
}
